﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc.UI;
using Microsoft.Practices.Unity;
using Microhard.WebUI.Models;
using Telerik.Web.Mvc;
using Microhard.Permission.Models;
using Microhard.Permission.Interface;
using Microhard.Framework.MVCHelper;
using FluentValidation.Mvc;
using Microhard.Core.DBUtility;
using Microhard.Permission.MVCFilter;

namespace Microhard.WebUI.Areas.Admin.Controllers
{
    public class GroupController : MicroHardBaseController<Group>
    {
        private IGroup _group = null;
        [Dependency]
        public IGroup group
        {
            set
            {
                base._repository = _group = value;
            }
            get
            {
                return _group;
            }

        }

        public override System.Web.Mvc.ActionResult Index(ScopeResult scope)
        {
            return View();
        }

        public override ActionResult _ListWithNoPaging(Group model,ScopeResult scope)
        {
            var rtn = _group.GetGroup();
            return new JsonResult
            {
                Data = rtn,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

        [MVCFilterAtrForLogon()]
        [MVCFilterAtrForResourcePermission(OperationKeyName = "Index")]
        public ActionResult GetSelectList(AttriubteOfSelectList ctrAttr)
        {
            var groups = _group.GetAllWithNoStruct();
            ctrAttr.Data = groups.Select(r => new SelectData
            {
                ID = r.ID.ToString(),
                Name = r.Name
            }).ToList();
            return View("SelectList", ctrAttr);
        }

        [MVCFilterAtrForLogon()]
        [MVCFilterAtrForResourcePermission(OperationKeyName = "Index")]
        public ActionResult _GetAllUsers(Guid groupID)
        {
            var users = _group.GetUserFromGroup(groupID);

            return new JsonResult()
            {
                Data = users,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

        }
    }
}
